from rest_framework import serializers
from .models import Image

class ImageUploadSerializer(serializers.ModelSerializer):
    class Meta:
        model = Image
        fields = ['id', 'image_type', 'image', 'description']
        read_only_fields = ['id', 'user']


class ImageSerializer(serializers.ModelSerializer):
    image_url = serializers.SerializerMethodField()
    
    class Meta:
        model = Image
        fields = ['id', 'image_type', 'image_url', 'description', 'created_at']
        read_only_fields = ['id', 'user', 'created_at']
    
    def get_image_url(self, obj):
        if obj.image:
            return obj.image.url
        return None